package sysAuth

import initConfig.SysInitData

class SysUsers   {

    String userNo; //用户ID:初始化admin密码admin
    String userName ;
    String passWord ;//用户名称
    String phone; //电话号码
    String gender; //性别
    String email; //邮箱
    String birth ;//生日
    Date loginTime; //登录时间
    Date logoffTime; //登出时间
    String qq;
    String weiXin ;//微信
    String isActive = "1";
    Long deptId;//部门
    Long orgId;
    /////// 18-11-21 新增
    String education ;//学历
    String position; //岗位
    Float salary = 0;
    String address;
    //////
    String creator ;//操作人
    String updater;//最近一次更新人
    Date dateCreated;
    Date lastUpdated;


    static constraints = {
        userNo(nullable: false,blank: false,unique: true)
        userName(nullable: false)
        orgId(nullable: false)
        passWord(nullable: false,blank: false)
        phone (nullable: true)
        gender (nullable: true)
        email (nullable: true)
        birth  (nullable: true)
        loginTime (nullable: true)
        logoffTime (nullable: true)
        qq (nullable: true)
        weiXin (nullable: true)
        isActive(nullable: false )
        deptId (nullable: true)
        creator(nullable: false)
        updater(nullable: true)
        education(nullable: true)
        position(nullable: true)
        salary(nullable: true)
        address(nullable: true)

    }

    static mapping = {
        version false
    }

    /**
     * 初始数据
     * @return
     */
    static init (){
        if(SysUsers.count !=0){
            return
        }
        SysUsers userAdmin = SysUsers.newInstance()
        userAdmin.setUserNo(SysInitData.SYS_ADMIN)
        userAdmin.setUserName(SysInitData.SYS_ADMIN)
        userAdmin.setPassWord("1".encodeAsMD5())
        userAdmin.setCreator(SysInitData.SYS_ADMIN)
        userAdmin.setDeptId(SysDepartments.first().id)
        userAdmin.setOrgId(SysOrganization.first().id)
        userAdmin.save(flush: true)

        userAdmin = SysUsers.newInstance()
        userAdmin.setUserNo(SysInitData.TEST_NAME)
        userAdmin.setUserName(SysInitData.TEST_NAME)
        userAdmin.setPassWord("1".encodeAsMD5())
        userAdmin.setCreator(SysInitData.SYS_ADMIN)
        userAdmin.setDeptId(SysDepartments.last().id)
        userAdmin.setOrgId(SysOrganization.last().id)
        userAdmin.save(flush: true)
    }
}
